/*
* character.cpp
*
*/
#include "character.h"
#include "consts.h"

/* Constructor 1
*   @arg:
*     - const char * path : path to text file
*/
Character::Character(const char * path) {
  __readFile(path);
  _status = 0;
  _view = VIEW_RIGHT;
  _vec[0] = _vec[1] = 0;
  _life = 5;
  /* HUD */
  _HUDLife = new HUD(60, 12);
  _HUDLife->_background = load_bitmap("images/hud/life/life_background.bmp", NULL);
  _HUDLife->__setX(8);
  _HUDLife->__setY(400);

  for(int i = 0; i < 5; ++i) {
    _HUDLife->_elementArr[i] = new Sprite("images/hud/life/pill.bmp");
    _HUDLife->_elementArr[i]->__setX(i * 12);
  }
  _HUDLife->__update();
}


void Character::__hit() {
  //return;
  if ( _status & STATUS_GUARD ) return;
  --_life;
  if ( _life >= 0 ) _HUDLife->_hideArr[_life] = 1;
  _HUDLife->__update();
}

void Character::__heal(int val) {
  if ( val < 1 ) return;
  int i = _life;
  _life += val;
  if ( _life > MAX_LIFE ) _life = MAX_LIFE;
  for(; i < _life; ++i) _HUDLife->_hideArr[i] = 0;
  _HUDLife->__update();
}

int Character::__getLife() { return _life; }

void Character::__linkEntVec(vector<Entity *>* entVec) { _entVec = entVec; }
